var canJump = function(nums) {
  const len = nums.length;
  if ( len <= 1) {
    return true;
  }
  // 记录当前能跳到的最大位置
  let max = 0;
  for (let i = 0; i < len; i++) {
    max = Math.max(i + nums[i], max);
    if (max >= len - 1) return true;
    if (max === i) return false;
  }
}

const nums = [2,3,1,1,4];
const nums1 = [3,2,1,0,4];
console.log(canJump(nums));
console.log(canJump(nums1));